﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HousingInfo.Library;

namespace NEWS.Admin
{
    public partial class SubTopicForums : System.Web.UI.Page
    {
        private static SubTopicForumBO subtopicforumbo;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                drlchuyenmuc.DataSource = CategoryInfo.GetCategoryInfo_BySingle(false, true, false, false,false);
                drlchuyenmuc.DataBind();
                drlchuyenmuc.Items.Insert(0, "Tất cả");
                GridView1.DataSource = SubTopicForumBOList.GetAllSubTopicForumBOList();
                GridView1.DataBind();
                drldanhmuc.DataSource = CategoryInfo.GetCategoryInfo_BySingle(false, true, false, false, false);
                drldanhmuc.DataBind();
            }
            else 
            {
            
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int subtopic4rum = Convert.ToInt32(lblmachude.Text);
            subtopicforumbo = SubTopicForumBO.GetSubTopicForumBO(subtopic4rum);
            subtopicforumbo.CategoryID = Convert.ToInt32(drldanhmuc.SelectedValue);
            subtopicforumbo.SubTopicForumName = txttenchude.Text;
            subtopicforumbo.SubTopicDescription = txtmota.Text;
            subtopicforumbo.IsActive = isActive.Checked;
            try
            {
                subtopicforumbo.Save();
                message.Text = "Cập nhật thành công !";
            }
            catch
            {
                message.Text = "Cập nhật thất bại !";
            }
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            PanelActions.Visible = false;
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

            int subtopic4rumid= Convert.ToInt32(GridView1.SelectedRow.Cells[2].Text);
            subtopicforumbo = SubTopicForumBO.GetSubTopicForumBO(subtopic4rumid);
            drldanhmuc.SelectedValue = subtopicforumbo.CategoryID.ToString();
            lblmachude.Text = subtopicforumbo.SubTopicForumID.ToString();
            drldanhmuc.SelectedValue = subtopicforumbo.CategoryID.ToString();
            string ten = drldanhmuc.SelectedValue;
            txttenchude.Text = subtopicforumbo.SubTopicForumName;
            txtmota.Text = subtopicforumbo.SubTopicDescription;
            isActive.Checked = subtopicforumbo.IsActive;
            PanelActions.Visible = true;
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

        protected void btndangtin_Click(object sender, EventArgs e)
        {
            PanelActions.Visible = true;
            subtopicforumbo.CategoryID = Convert.ToInt32(drldanhmuc.SelectedValue);
            subtopicforumbo.SubTopicForumName = txttenchude.Text;
            subtopicforumbo.SubTopicDescription = txtmota.Text;
            subtopicforumbo.IsActive = isActive.Checked;
            try
            {
                subtopicforumbo.Save();
                message.Text = "Thêm thành công";
            }
            catch
            {
                message.Text = "Thêm thất bại";
            }
        }

        protected void btnxoatin_Click(object sender, EventArgs e)
        {

        }

        protected void drlchuyenmuc_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (drlchuyenmuc.SelectedValue == "Tất cả")
            {
                GridView1.DataSource = SubTopicForumBOList.GetAllSubTopicForumBOList();
                GridView1.DataBind();
            }
            else
            {
                GridView1.DataSource = SubTopicForumBOList.GetSubTopicForumBOList_ByID(Convert.ToInt32(drlchuyenmuc.SelectedValue));
                GridView1.DataBind();
            }
            messagedelete.Text = "";
        }
    }
}
